package com.software.authentication.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONException;

import com.software.common.CommonUtils;
import com.software.driver.dao.DriverTransaction;
import com.software.lineragent.dao.LinerAgentTransaction;
import com.software.motorcade.dao.MotorcadeTransaction;
import com.software.shipper.dao.ShipperTransaction;
import com.software.shipperagent.dao.ShipperAgentTransaction;

public class AuthServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.sendRedirect("/Software/error.html");
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String email = (String) request.getSession(true).getAttribute("user");
		String role = (String) request.getSession(true).getAttribute("role");
		if(email == null || role == null || email.equals("") || role.equals("")){
			response.sendRedirect("/Software/index.html");
			return;
		}
		if(role.equals("Shipper"))
			response.sendRedirect("/Software/shipperhome.html?user="+email);
		else if(role.equals("ShippingAgent"))
			response.sendRedirect("/Software/sagenthome.html?user="+email);
		else if(role.equals("LinerAgent"))
			response.sendRedirect("/Software/lagenthome.html?user="+email);
		else if(role.equals("Motorcade"))
			response.sendRedirect("/Software/motohome.html?user="+email);
		else if(role.equals("Driver"))
			response.sendRedirect("/Software/driverhome.html?user="+email);
	}
}
